package com.itheima.controller;


import com.itheima.exception.MyException.HaveStudentException;
import com.itheima.pojo.*;
import com.itheima.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;


//班级管理
@RestController
public class ClazzController {
    @Autowired
    ClazzService cs;
    //班级管理条件查询
    @GetMapping("/clazzs")
    public Result getClazz(ClazzQueryParam cqp){
        PageResult<Clazz> p1= cs.getClazz(cqp);
        return Result.success(p1);
    }
   // 添加班级
    @PostMapping("/clazzs")
    public Result addclazz(@RequestBody Clazz c){
        cs.addclazz(c);
        return Result.success();
    }
    //根据id查询班级
    @GetMapping("/clazzs/{id}")
    public Result idfind(@PathVariable Integer id){
      Clazz c1= cs.idfind(id);
        return Result.success(c1);
    }
    //修改数据
    @PutMapping("/clazzs")
    public Result updateclazz(@RequestBody Clazz c){
        cs.updateclazz(c);
        return Result.success();
    }
    //删除班级
    @DeleteMapping("/clazzs/{id}")
    public Result deleteclazz(@PathVariable Integer id)throws HaveStudentException {
        cs.deleteclazz(id);
        return Result.success();
    }

    //学生管理在新增学院的时候展示所有的班级
    @GetMapping("/clazzs/list")
    public Result getclazlist(){
        return  Result.success(cs.getclazzlist());
    }

}
